如果直接 import $ from ‘./jquery.min’ 引入的话,会报错。
webpack 下使用jQuery ,要先安装。
在index.js 的目录下,执行以下命令:1
npm install jquery -D
在js里引入jquery1
import $ from 'jquery'
在webpack react项目里怎么使用jQuery的插件?
修改组建源码,将方法暴露出去。1
2
3
4
5
6
7
8
9function reflection($) {
$.fn.reflect = function(options) {
options = $.extend({
height: 1/3,
opacity: 0.5
}, options);
return this.unreflect().each(function() {
将方法暴露出去
1 |
|
在js中引用1
2
3
4
5
6import $ from 'jquery';
import cloud9carousel from './../js/jquery.cloud9carousel';
import reflection from './../js/jquery.reflection';
//初始化组件
cloud9carousel($);
reflection($);